# -*- coding: utf-8 -*-
from django import forms

from google.appengine.ext import db

from reports.models import DeseaseReport

class ReportForm(forms.Form):
    
    def __init__(self, id=None, *args, **kwargs):
        super(ReportForm, self).__init__(*args, **kwargs)
        if id is not None:
            self.fields['overview'].widget.attrs.update({"id":id,})
            
    overview = forms.CharField(label='', widget=forms.Textarea(attrs={"class":"overview", "cols":"75", "rows":"15"}), required=True)
    
    def clean_overview(self):
        overview = self.cleaned_data['overview'].strip()
        if not overview:
            raise forms.ValidationError(u"This field is required")
        return overview
        
        
    def save(self, report, key):
        d = self.cleaned_data
        
        report.__setattr__(key, d['overview'])
        report.put()
        return d['overview']
        
    